﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class news : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sort = "1";
            if (null != Request.QueryString["s"])
            {
                sort = Request.QueryString["s"].ToString();
            }
            InitLeftNav(Convert.ToInt32(sort));
            if (sort == "1")
            {
                this.ltlicon1.Text = "<img src=\"images/news/news_icon.png\" alt=\"\" />";
            }
            else
            {
                this.ltlicon2.Text = "<img src=\"images/news/news_icon.png\" alt=\"\" />";
            }
            if (null != Request.QueryString["id"])
            {
                InitTopNav(sort, Request.QueryString["id"].ToString());
                InitContent(Request.QueryString["id"].ToString());
            }
        }
    }

    private void InitLeftNav(int sort)
    {
        CNews news = new CNews();
        DataTable dt = news.ReadNewses(sort);
        StringBuilder sb = new StringBuilder();
        if (null != dt)
        {
            if (null == Request.QueryString["id"])
            {
                InitTopNav(sort.ToString(), dt.Rows[0]["id"].ToString());
                InitContent(dt.Rows[0]["id"].ToString());
            }
            sb.Append("<ul>");
            foreach (DataRow r in dt.Rows)
            {
                sb.Append("<li><a href=\"news.aspx?s=" + sort.ToString() + "&id=" + r["id"].ToString() + "\">■" + r["title"].ToString() + "</a></li>");
            }
            sb.Append("</ul>");
        }
        this.ltlList.Text = sb.ToString();
    }

    private void InitTopNav(string sort, string id)
    {
        CNews news = new CNews();
        DataRow r = news.ReadNews(Convert.ToInt32(id));
        StringBuilder sb = new StringBuilder();
        if (sort == "1")
        {
            sb.Append("<a href=\"news.aspx?s=" + sort + "\">企业新闻</a>");
        }
        else
        {
            sb.Append("<a href=\"news.aspx?s=" + sort + "\">行业新闻</a>");
        }
        sb.Append(">");
        sb.Append( r["title"].ToString());
        this.ltlTopNav.Text = sb.ToString();
    }

    private void InitContent(string id)
    {
        CNews news = new CNews();
        DataRow r = news.ReadNews(Convert.ToInt32(id));
        this.ltlContent.Text = r["content"].ToString();
    }
}